﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MyVoteMVC.Common.Objects
{
    public class MailMessage:ICloneable
    {
        public Encoding _encoding = Encoding.UTF8;
        public Encoding Encoding
        {
            get
            {
                return _encoding;
            }
        }

        public string From { get; set; }

        public List<string> Tos { get; set; }

        public string DisplayFrom { get; set; }

        public List<string> DisplayTos { get; set; }

        public List<string> WrongTos { get; set; }

        public string Subject { get; set; }

        public string Body { get; set; }

        public bool IsBodyHtml { get; set; }

        public List<string> Attachment { get; set; }

        public Dictionary<string, byte[]> AttachmentData { get; set; }

        public object Tag { get; set; }

        private System.Net.Mail.MailPriority _priority = System.Net.Mail.MailPriority.Normal;
        public System.Net.Mail.MailPriority Priority 
        {
            get { return _priority; }
            set { _priority = value; }
        }

        public MailMessage()
        {
            Tos = new List<string>();
            Attachment = new List<string>();
            AttachmentData = new Dictionary<string, byte[]>();
            DisplayTos = new List<string>();
            WrongTos = new List<string>();
        }

        public void AddTo(string to)
        {
            Tos.Add(to);
        }


        #region ICloneable Members

        public object Clone()
        {
            MailMessage _clone = new MailMessage();
            _clone._encoding = this._encoding;
            _clone._priority = this._priority;

            _clone.Attachment = new List<string>();
            foreach (string attach in this.Attachment)
            {
                _clone.Attachment.Add(attach);
            }

            _clone.AttachmentData = new Dictionary<string, byte[]>();
            foreach (KeyValuePair<string, byte[]> kvp in this.AttachmentData)
            {
                _clone.AttachmentData.Add(kvp.Key, kvp.Value);
            }

            _clone.Body = this.Body;
            _clone.DisplayFrom = this.DisplayFrom;

            _clone.DisplayTos = new List<string>();
            foreach (string displayTo in this.DisplayTos)
            {
                _clone.DisplayTos.Add(displayTo);
            }
            _clone.From = this.From;
            _clone.IsBodyHtml = this.IsBodyHtml;
            _clone.Subject = this.Subject;
            _clone.Tag = this.Tag;

            _clone.Tos = new List<string>();
            foreach (string to in this.Tos)
            {
                _clone.Tos.Add(to);
            }

            return _clone;
        }

        #endregion
    }
}
